using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Network;
using MicroMsg.Plugin.FaceBook;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace MicroMsg.UI.Page
{
	public class MainPage : ChatContainerPage, LanguageListener
	{
		private const string TAG = "MainPage";
		private const int PARAM_FIRST_PAGESWITCH = 0;
		private const int PARAM_SECOND_AUTHRET = 1;
		private const string nMainPageSelectedIndexKey = "nMainPageSelectedIndex";
		private const string bHasAskOpenPushKey = "bHasAskOpenPush";
		private const string bHasAskOpenLbsKey = "bHasAskOpenLbsKey";
		public const string CStrKeyBJustRegUser = "KeyBJustRegUser";
		private const int ContactViewIndex = 1;
		private const int SessionViewIndex = 0;
		private const int FindFriendViewIndex = 2;
		private SessionView tSessionView;
		private ContactsView tContactView;
		private FindFriendView tFindFriendView;
		private EventWatcher m_WatcherNeedDoSync;
		private EventWatcher m_WatcherGetUpdateInfoSuccess;
		private EventWatcher m_WatcherAutoAuthSuccess;
		private EventWatcher m_WatcherServerBulletin;
		private EventWatcher m_WatcherLanguage;
		private EventWatcher m_GetVersionOK;
		private EventWatcher m_StatusChange;
		public static MainPage mainPageInstance = null;
		private AuthResponse mAuthRet;
		private UpdateInfo mUpdateinfo;
		public int mNBackKeyRelayCount;
		private bool canShowDisconnect;
		public UpdateInfo m_UpdateInfo;
		private bool mBIsGotFirstFrame;
		private bool mBIsFirstPageIn = true;
		private bool mBIsPageInTop;
		private EventWatcher mPushOverWatcher;
		private MMMessageBox mUpdateInfoDlg;
		private IApplicationBar mAppBarHidden;
		private bool mBIsPageInited;
		private bool mBPageFirstLoaded;
		private static TestContactItemCtrl testContactView = null;
		private bool mBIsLoggedOut;
		private static EventWatcher mWatcherLogOut;
		private EventWatcher mAuthChangeWatcher;
		private static List<string> sListStrToToast = new List<string>();
		private int unReadMsgCount;
		private EventWatcher mWatcherNetStatus;
		private EventWatcher mWatcherSyncStatus;
		public HeadImgLoadService mHeadImgLoadService = new HeadImgLoadService(true);
		public ContactUpdatedService mContactUpdatedService = new ContactUpdatedService();
		public bool IsNeedOnlyShowVisibleItem = true;
		private List<UIElement> mUiToHideList;
		private bool mBIsUpdated;
		private EventWatcher mBindGuideInit;
		private EventWatcher mBindQQSuccessInit;
		private EventWatcher mBindPhoneSuccessInit;
		public static bool IsRegisterFromFacebook = false;
		private EventWatcher friendsSuccessWatcher;
		private EventWatcher friendsFailWatcher;
		private List<string> fbFriends;
		private EventWatcher m_WatcherAddContact;
		private EventWatcher m_WatcherVerifyContact;
		private EventWatcher mWatchFirstSync;
		private object mObjectWatcher = new object();
		internal Grid LayoutRoot;
		internal Grid ContentPanel;
		internal Pivot mPivotControl;
		internal Grid gridSessionView;
		internal Grid gridContactsView;
		internal Grid gridFFView;
		internal panelTitleControl panel1Line;
		internal TextBlock unreadMsgNum;
		internal TextBlock netStatusTxt;
		internal TextBlock disConnectTxt;
		internal PerformanceProgressBar NetStatusProgressBar;
		private bool _contentLoaded;
		public SessionView mSessionView
		{
			get
			{
				return this.getSessionView();
			}
		}
		public ContactsView mContactView
		{
			get
			{
				return this.getContactView();
			}
		}
		public FindFriendView mFindFriendView
		{
			get
			{
				return this.getFFView();
			}
		}
		public SessionView getSessionView()
		{
			if (this.tSessionView == null)
			{
				SessionView sessionView = new SessionView();
				sessionView.set_Height(650.0);
				sessionView.set_Margin(new Thickness(0.0));
				this.gridSessionView.get_Children().Clear();
				this.gridSessionView.get_Children().Add(sessionView);
				this.tSessionView = sessionView;
			}
			return this.tSessionView;
		}
		public ContactsView getContactView()
		{
			if (this.tContactView == null)
			{
				ContactsView contactsView = new ContactsView();
				contactsView.mContactViewType = ContactsViewType.CONTACT_VIEW_MAIN;
				contactsView.set_Height(640.0);
				this.gridContactsView.get_Children().Clear();
				this.gridContactsView.get_Children().Add(contactsView);
				this.tContactView = contactsView;
			}
			return this.tContactView;
		}
		public FindFriendView getFFView()
		{
			if (this.tFindFriendView == null)
			{
				this.tFindFriendView = new FindFriendView();
				this.gridFFView.get_Children().Clear();
				this.gridFFView.get_Children().Add(this.tFindFriendView);
			}
			return this.tFindFriendView;
		}
		private void pageFirstFrameShown()
		{
			Profiler.setPoint("FisrtFrameShown");
			Profiler.printfProfile();
			this.guideToSetHeadImg();
			this.m_WatcherNeedDoSync = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerCoverEvent));
			this.m_WatcherAutoAuthSuccess = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerAutoAuthSuccess));
			this.m_WatcherServerBulletin = new EventWatcher(this, null, new EventHandlerDelegate(this.mSessionView.onEventServerBulletinChanged));
			this.m_WatcherLanguage = new EventWatcher(this, null, new EventHandlerDelegate(this.mSessionView.onEventLanguageChanged));
			this.m_GetVersionOK = new EventWatcher(this, null, new EventHandlerDelegate(this.onGetVersionOK));
			this.m_StatusChange = new EventWatcher(this, null, new EventHandlerDelegate(this.onStatusChanged));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_BEGIN, this.m_WatcherNeedDoSync);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_CONTINUE, this.m_WatcherNeedDoSync);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_FINISH, this.m_WatcherNeedDoSync);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_ERR, this.m_WatcherNeedDoSync);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTOAUTH_SUCCESS, this.m_WatcherAutoAuthSuccess);
			EventCenter.registerEventWatcher(EventConst.ON_NET_BULLETIN, this.m_WatcherServerBulletin);
			EventCenter.registerEventWatcher(EventConst.ON_UI_LANGUAGE_CHANGED, this.m_WatcherLanguage);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_GetVersionOK);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SYNC_WEIN_STATUS, this.m_StatusChange);
			if (this.mBIsFirstPageIn)
			{
				this.ContentPanel.set_Visibility(1);
				ServiceCenter.sceneGetUpdateInfo.doScene(UpdateType.UPDATETYPE_MANUAL);
			}
			this.NetStatusDetectInit();
			this.SyncStatusDetectInit();
			this.canShowDisconnect = false;
			LanguageRefreshManager.GetInstance().Add(this);
			this.mSessionView.InitBanner();
			this.BindGuideInit();
			FaceBookMgr.DelaySaveTokenTime();
			this.getSessionView();
			base.get_Dispatcher().BeginInvoke(delegate
			{
			});
		}
		public MainPage()
		{
			Profiler.setPoint("MainPageStart");
			BannerManager.test();
			MainPage.mainPageInstance = this;
			this.InitializeComponent();
			if (MMTheme.getSystemThemeType() == MMThemeTypes.COOL_BLACK_THEME)
			{
				this.mPivotControl.set_Background(null);
			}
			base.add_Loaded(new RoutedEventHandler(this.MainPage_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.MainPage_Unloaded));
			base.add_LayoutUpdated(new EventHandler(this.MainPage_LayoutUpdated));
			base.set_ApplicationBar(SessionView.GetApplicationBar(true));
			this.setAppBarStyle(base.get_ApplicationBar());
			this.initAuthEventWatcher();
			Profiler.setPoint("MainPageEnd");
		}
		private void MainPage_LayoutUpdated(object sender, EventArgs e)
		{
			if (this.mBIsGotFirstFrame)
			{
				return;
			}
			base.remove_LayoutUpdated(new EventHandler(this.MainPage_LayoutUpdated));
			this.mBIsGotFirstFrame = true;
		}
		~MainPage()
		{
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (TestUserChecker.IsTestVersion())
			{
				panelTitleControl expr_0D = this.panel1Line;
				expr_0D.strTitle += "测试版";
			}
			Profiler.setPoint("OnPageInStart");
			Log.smethod_5("MainPage", "OnPageIn");
			if (object_0 != null && object_0.Length > 1 && object_0[1] != null && object_0[1].GetType() == typeof(AuthResponse))
			{
				this.checkIsNeedUpdatePrompt((AuthResponse)object_0[1]);
			}
			Profiler.setPoint("OnPageInEnd");
		}
		protected override void OnPageOut()
		{
			this.NetStatusDetectUint();
			this.SyncStatusDetectUnit();
			this.mHeadImgLoadService.Unit();
			this.BindGuideUninit();
			LanguageRefreshManager.GetInstance().Delete(this);
		}
		protected override void OnPageBack()
		{
			base.PreOnPageBack();
			this.mBIsPageInTop = true;
		}
		protected override void OnPageForward(Uri targetPage)
		{
			this.mBIsPageInTop = false;
			base.PreOnPageForward(targetPage);
		}
		private void LoadHistory()
		{
		}
		private void SavaHistory()
		{
			ConfigMgr.setInt("nMainPageSelectedIndex", this.mPivotControl.SelectedIndex);
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (base.PreOnBackKeyPress(cancelEventArgs_0))
			{
				return;
			}
			if (cancelEventArgs_0.get_Cancel())
			{
				Log.smethod_5("MainPage", "OnBackKeyPress:true == e.Cancel");
				return;
			}
			if (0 < this.mNBackKeyRelayCount)
			{
				Log.smethod_5("MainPage", "OnBackKeyPress:mNBackKeyRelayCount");
				cancelEventArgs_0.set_Cancel(true);
				return;
			}
			cancelEventArgs_0.set_Cancel(true);
			Log.smethod_5("MainPage", "OnBackKeyPress:mPivotControl.SelectedIndex");
			if (ConfigMgr.getBool("Set_Common_ToggleExitComfirm", true))
			{
				bool checkBool;
				MMMessageBox mMMessageBox;
				if (!(checkBool = (GConfigMgr.settings.bIsNewMsgNotifyOn || ServiceCenter.pushNotifyMgr.isEnable())))
				{
					if (ConfigMgr.getBool("MainPageFirstExitPragram", true))
					{
						checkBool = true;
					}
					mMMessageBox = MMMessageBox.Show_Check(strings.MainPage_MsgExitTitle, "", true, strings.MainPage_MsgNotifyOn, checkBool, strings.COM_Yes, strings.COM_No);
				}
				else
				{
					mMMessageBox = MMMessageBox.Show(strings.MainPage_MsgExitTitle, "", true, strings.COM_Yes, strings.COM_No);
				}
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.BackKeyDlgReturn);
				return;
			}
			Log.smethod_5("MainPage", "User Close App");
			App.ExitProgram();
		}
		public void ToPrevView()
		{
			if (this.mPivotControl.SelectedIndex != 0)
			{
				this.mPivotControl.SelectedIndex--;
			}
		}
		public void ToIndex(int nIndex, bool bForceTo = false)
		{
			if (nIndex >= 0 && nIndex < this.mPivotControl.get_Items().get_Count() && bForceTo)
			{
				this.mPivotControl.SelectedIndex = nIndex;
			}
		}
		public void ChangeToSessionView()
		{
			if (this.mPivotControl.SelectedIndex == 0)
			{
				return;
			}
			this.ToIndex(0, true);
		}
		public void BackKeyDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			int userClickResult = MMMessageBox.GetUserClickResult(dlgReturnEventArg_0);
			bool flag = GConfigMgr.settings.bIsNewMsgNotifyOn || ServiceCenter.pushNotifyMgr.isEnable();
			if (userClickResult == 0)
			{
				ConfigMgr.setBool("MainPageFirstExitPragram", false);
				if (!flag)
				{
					if (MMMessageBox.GetUserCheckResult(dlgReturnEventArg_0) == 1)
					{
						GConfigMgr.settings.bIsNewMsgNotifyOn = true;
						ServiceCenter.pushNotifyMgr.setEnable(true);
						GConfigMgr.saveSetting();
						this.mPushOverWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_PushOver_EventHandler));
						EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_PUSHCHANNEL_REG_OVER, this.mPushOverWatcher);
						this.disableAllControls();
						ServiceCenter.pushNotifyMgr.openPushChannelForExit();
						return;
					}
					Log.smethod_5("MainPage", "BackKeyDlgReturn: User Click Yes To Close App");
					App.ExitProgram();
					return;
				}
				else
				{
					Log.smethod_5("MainPage", "BackKeyDlgReturn: User Click Yes To Close App");
					App.ExitProgram();
				}
			}
		}
		public void on_PushOver_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.enableAllControls();
			Log.smethod_5("MainPage", "BackKeyDlgReturn: User Click Yes To Close App");
			App.ExitProgram();
		}
		private void onEventHandlerAutoAuthSuccess(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.checkIsNeedUpdatePrompt((AuthResponse)evtArgs.mObject);
		}
		private void checkIsNeedUpdatePrompt(AuthResponse authRet)
		{
			this.mAuthRet = authRet;
			if (this.mAuthRet.BaseResponse.Ret == -16)
			{
				Log.smethod_5("MainPage", "Critical update");
				MainPage.logOut();
				this.mUpdateInfoDlg = MMMessageBox.Show(strings.MainPage_MsgUpdateTitle, strings.MainPage_MsgUpdateContent, false, strings.MainPage_MsgUpdateBtnL, strings.COM_Exit);
				this.mUpdateInfoDlg.ReturnEvent = new DlgReturnEvent(this.updateInfoDlgReturn);
				return;
			}
			if (this.mAuthRet.BaseResponse.Ret == -17)
			{
				Log.smethod_4("MainPage", "Recommended update");
				if (GConfigMgr.settings.lastUpdatePromptedClientVersion != this.mAuthRet.NewVersion && this.m_WatcherGetUpdateInfoSuccess == null)
				{
					this.m_WatcherGetUpdateInfoSuccess = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerGetUpdateInfo));
					EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_WatcherGetUpdateInfoSuccess);
					ServiceCenter.sceneGetUpdateInfo.doScene(UpdateType.UPDATETYPE_RECOMMENDED);
				}
			}
		}
		private void onEventHandlerCoverEvent(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_PROCESS_NEWINIT_BEGIN)
			{
				ProcessingCover.getProgressBar(this.LayoutRoot, strings.MainPage_MsgSyncing, null, false, false, null);
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_PROCESS_NEWINIT_FINISH)
			{
				ProcessingCover.setCurrentProgress(-1);
				ProcessingCover.releaseProgressBar(this.LayoutRoot);
				this.initAfterSyncDone();
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_PROCESS_NEWINIT_CONTINUE)
			{
				int currentProgress = Convert.ToInt32(evtArgs.mObject);
				ProcessingCover.setCurrentProgress(currentProgress);
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_PROCESS_NEWINIT_ERR)
			{
				ProcessingCover.setCurrentProgress(-1);
				ProcessingCover.releaseProgressBar(this.LayoutRoot);
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.MainPage_MsgUpdateFailed, "", false, strings.COM_Retry, strings.COM_Exit);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.initFailedMsgBoxHandler);
			}
		}
		private void initFailedMsgBoxHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				ServiceCenter.sceneNewSync.doScene(7, syncScene.MM_NEWSYNC_SCENE_OTHER);
				return;
			case 1:
				MainPage.doInitLoOut();
				return;
			default:
				MainPage.doInitLoOut();
				return;
			}
		}
		private void initAfterSyncDone()
		{
		}
		private void onEventHandlerGetUpdateInfo(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_WatcherGetUpdateInfoSuccess);
			this.m_WatcherGetUpdateInfoSuccess = null;
			this.mUpdateinfo = (UpdateInfo)evtArgs.mObject;
			if (this.mUpdateinfo != null)
			{
				if (this.mAuthRet.BaseResponse.Ret == -16)
				{
					return;
				}
				if (this.mAuthRet.BaseResponse.Ret == -17 && this.mUpdateinfo.PackVersion != ConstantsProtocol.CLIENT_VERSION && GConfigMgr.settings.lastUpdatePromptedClientVersion != this.mUpdateinfo.PackVersion)
				{
					string text = (this.mUpdateinfo.PackSize * 1.0 / 1048576.0).ToString();
					int num = (text.get_Length() > 3) ? 3 : text.get_Length();
					text = text.Substring(0, num);
					this.mUpdateInfoDlg = MMMessageBox.Show(strings.Set_AboutMM_HasNewVersion, string.Concat(new string[]
					{
						this.mUpdateinfo.PackDescription,
						"\r\n",
						strings.Set_AboutMM_PackageSize,
						text,
						"MB"
					}), true, strings.MainPage_MsgUpdateBtnL, strings.COM_Cancel);
					this.mUpdateInfoDlg.ReturnEvent = new DlgReturnEvent(this.updateInfoDlgReturn);
					GConfigMgr.settings.lastUpdatePromptedClientVersion = this.mUpdateinfo.PackVersion;
					GConfigMgr.saveSetting();
				}
			}
		}
		private void onGetVersionOK(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.m_UpdateInfo = (evtArgs.mObject as UpdateInfo);
			if (this.mContactView != null)
			{
				ContactsView.GetApplicationBar(false);
			}
			if (this.mSessionView != null)
			{
				SessionView.GetApplicationBar(false);
			}
			if (this.mFindFriendView != null)
			{
				FindFriendView.GetApplicationBar(false);
			}
			if (this.mPivotControl.SelectedIndex == 1)
			{
				base.set_ApplicationBar(ContactsView.GetApplicationBar(true));
			}
			else
			{
				if (this.mPivotControl.SelectedIndex == 0)
				{
					base.set_ApplicationBar(SessionView.GetApplicationBar(true));
				}
				else
				{
					if (this.mPivotControl.SelectedIndex == 2)
					{
						base.set_ApplicationBar(FindFriendView.GetApplicationBar(true));
					}
					else
					{
						base.set_ApplicationBar(SessionView.GetApplicationBar(true));
					}
				}
			}
			if (this.m_GetVersionOK != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_GetVersionOK);
				this.m_GetVersionOK = null;
			}
		}
		private void onStatusChanged(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			NetSceneWeixinStatus netSceneWeixinStatus = evtArgs.mObject as NetSceneWeixinStatus;
			if (netSceneWeixinStatus == null)
			{
				return;
			}
			if (netSceneWeixinStatus.isWebWeiXinLogin)
			{
				if (this.mSessionView != null && !WebMMMgr.IsWebMMOnline)
				{
					WebMMMgr.IsWebMMOnline = true;
					this.mSessionView.setWebMMState(true);
				}
				return;
			}
			if (this.mSessionView != null && WebMMMgr.IsWebMMOnline)
			{
				WebMMMgr.IsWebMMOnline = false;
				this.mSessionView.setWebMMState(false);
			}
		}
		public void updateInfoDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			this.mUpdateInfoDlg = null;
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case -1:
				this.cancelUpdate();
				return;
			case 0:
				this.startUpdate();
				return;
			case 1:
				this.cancelUpdate();
				return;
			default:
				return;
			}
		}
		public void startUpdate()
		{
			Log.smethod_5("MainPage", "begin update");
			Util.doUpdateApp();
			Log.smethod_7();
			App.ExitProgram();
		}
		public void cancelUpdate()
		{
			Log.smethod_5("MainPage", "cancel update");
			if (this.mAuthRet != null && this.mAuthRet.BaseResponse.Ret == -16)
			{
				App.ExitProgram();
			}
		}
		private void MainPage_Unloaded(object sender, RoutedEventArgs e)
		{
			if (base.get_ApplicationBar() != null)
			{
				this.mAppBarHidden = base.get_ApplicationBar();
				this.mAppBarHidden.set_IsVisible(false);
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				if (!this.mBIsPageInTop)
				{
					using (IEnumerator<object> enumerator = this.mPivotControl.get_Items().GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							PivotItem pivotItem = (PivotItem)enumerator.get_Current();
							if (this.mPivotControl.SelectedItem != pivotItem)
							{
								UIElement uIElement = pivotItem.get_Content() as UIElement;
								if (uIElement != null)
								{
									uIElement.set_Visibility(1);
								}
							}
						}
					}
				}
			});
		}
		public void DoNewSync()
		{
			if (this.mBIsFirstPageIn)
			{
				Log.smethod_5("MainPage", "DoNewSync");
				ServiceCenter.sceneNewSync.doScene(7, syncScene.MM_NEWSYNC_SCENE_OTHER);
				this.mBIsFirstPageIn = false;
			}
		}
		private bool canInitPage()
		{
			return !UpdateMgr.needUpdate();
		}
		public void initPage()
		{
			this.showAllToast();
			if (base.get_ApplicationBar() != null)
			{
				base.get_ApplicationBar().set_IsVisible(true);
				if (this.mAppBarHidden != null)
				{
					this.mAppBarHidden.set_IsVisible(true);
					this.mAppBarHidden = null;
				}
			}
			this.ContentPanel.set_Visibility(0);
			if (!this.tryShowPushDialog() && !this.tryShowLbsDialog())
			{
				NetSceneNewSync.isEnable = true;
			}
		}
		private bool tryShowPushDialog()
		{
			if (!ConfigMgr.getBool("bHasAskOpenPush", false) && GConfigMgr.settings.bIsNewMsgNotifyOn != ServiceCenter.pushNotifyMgr.isEnable())
			{
				ServiceCenter.pushNotifyMgr.setEnable(GConfigMgr.settings.bIsNewMsgNotifyOn);
			}
			if (!this.mBIsPageInited && !ConfigMgr.getBool("bHasAskOpenPush", false) && !GConfigMgr.settings.bIsNewMsgNotifyOn)
			{
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.MainPage_MsgAskPushTitle, "", true, strings.COM_Confirm, strings.COM_Cancel);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.askPushHandler);
				base.get_ApplicationBar().set_IsVisible(false);
				return true;
			}
			if (GConfigMgr.settings.bIsNewMsgNotifyOn)
			{
				ConfigMgr.setBool("bHasAskOpenPush", true);
			}
			return false;
		}
		public void askPushHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			base.get_ApplicationBar().set_IsVisible(true);
			int userClickResult = MMMessageBox.GetUserClickResult(dlgReturnEventArg_0);
			bool flag = false;
			switch (userClickResult)
			{
			case 0:
				flag = true;
				break;
			}
			NetSceneNewSync.isEnable = true;
			Log.smethod_4("MainPage", "NetSceneNewSync.isEnable is true");
			if (MainPage.mainPageInstance != null)
			{
				ServiceCenter.sceneNewSync.doScene(7, syncScene.MM_NEWSYNC_SCENE_OTHER);
			}
			if (flag)
			{
				GConfigMgr.settings.bIsNewMsgNotifyOn = true;
				ServiceCenter.pushNotifyMgr.setEnable(flag);
				GConfigMgr.saveSetting();
			}
			ConfigMgr.setBool("bHasAskOpenPush", true);
			if (!this.tryShowLbsDialog())
			{
				NetSceneNewSync.isEnable = true;
			}
		}
		private bool tryShowLbsDialog()
		{
			if (!this.mBIsPageInited && !ConfigMgr.getBool("bHasAskOpenLbsKey", false) && !ConfigMgr.getBool("bNotShowDialogInLbs", false))
			{
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.LBS_PrivacyTitle, "", true, strings.COM_Confirm, strings.COM_Cancel);
				mMMessageBox.TwoButtonViewMsgTxt.set_Visibility(1);
				RichTextBox richTextBox = new RichTextBox();
				richTextBox.set_VerticalAlignment(0);
				richTextBox.set_VerticalContentAlignment(0);
				richTextBox.set_Margin(new Thickness(-12.0));
				richTextBox.set_Width(444.0);
				Paragraph paragraph = new Paragraph();
				Run run = new Run();
				Run run2 = new Run();
				Hyperlink privacyLinkButton = SeePrivacyCtrl.GetPrivacyLinkButton(R.theme.DIALOG_TITLE_FONT_BRUSH);
				Hyperlink microsoftPrivacyLink = SeePrivacyCtrl.GetMicrosoftPrivacyLink(R.theme.DIALOG_TITLE_FONT_BRUSH);
				Run run3 = new Run();
				run.set_Text(strings.LBS_PrivacyTip1);
				run.set_FontSize(20.0);
				run.set_Foreground(MMTheme.GetInstance().DIALOG_CONTENT_FONT_BRUSH);
				run2.set_Text(strings.LBS_PrivacyTip2);
				run2.set_FontSize(20.0);
				run2.set_Foreground(MMTheme.GetInstance().DIALOG_CONTENT_FONT_BRUSH);
				if (R.isEnglish())
				{
					run3.set_Text(".");
				}
				else
				{
					run3.set_Text("。");
				}
				run3.set_Foreground(MMTheme.GetInstance().DIALOG_CONTENT_FONT_BRUSH);
				paragraph.get_Inlines().Add(run);
				paragraph.get_Inlines().Add(privacyLinkButton);
				paragraph.get_Inlines().Add(run2);
				paragraph.get_Inlines().Add(microsoftPrivacyLink);
				paragraph.get_Inlines().Add(run3);
				richTextBox.get_Blocks().Add(paragraph);
				mMMessageBox.CustomCtrlContainer.set_Visibility(0);
				mMMessageBox.CustomCtrlContainer.get_Children().Add(richTextBox);
				mMMessageBox.UpdateLayout();
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.askLbsHandler);
				base.get_ApplicationBar().set_IsVisible(false);
				return true;
			}
			if (ConfigMgr.getBool("bNotShowDialogInLbs", false))
			{
				ConfigMgr.setBool("bHasAskOpenLbsKey", true);
			}
			return false;
		}
		public void askLbsHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			base.get_ApplicationBar().set_IsVisible(true);
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				ConfigMgr.setBool("bNotShowDialogInLbs", true);
				break;
			}
			NetSceneNewSync.isEnable = true;
			Log.smethod_4("MainPage", "NetSceneNewSync.isEnable is true");
			if (MainPage.mainPageInstance != null)
			{
				ServiceCenter.sceneNewSync.doScene(7, syncScene.MM_NEWSYNC_SCENE_OTHER);
			}
			ConfigMgr.setBool("bHasAskOpenLbsKey", true);
		}
		private void MainPage_Loaded(object sender, RoutedEventArgs e)
		{
			if (!this.mBPageFirstLoaded)
			{
				this.pageFirstFrameShown();
				this.mBPageFirstLoaded = true;
			}
			using (IEnumerator<object> enumerator = this.mPivotControl.get_Items().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					PivotItem pivotItem = (PivotItem)enumerator.get_Current();
					UIElement uIElement = pivotItem.get_Content() as UIElement;
					if (uIElement != null)
					{
						uIElement.set_Visibility(0);
					}
				}
			}
			if (this.canInitPage())
			{
				this.initPage();
			}
			else
			{
				if (UpdateMgr.needUpdate())
				{
					this.startUpdateData();
				}
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				Log.smethod_5("MainPage", "MainPage_Loaded");
				GC.Collect();
			});
		}
		private void cons_SearchCompleted(object sender, PhoneNumEventArgs e)
		{
			if (e.Result != null)
			{
				StringBuilder stringBuilder = new StringBuilder();
				using (List<PhoneNumInfo>.Enumerator enumerator = e.Result.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						PhoneNumInfo current = enumerator.get_Current();
						stringBuilder.AppendLine(current.Name + ":" + current.Num);
					}
				}
				MMMessageBox.Show(stringBuilder.ToString(), true, "确定");
			}
		}
		private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (base.HasChatPageShow())
			{
				if (this.mPivotControl.SelectedIndex == 1)
				{
					this.getContactView();
					this.oldbar = ContactsView.GetApplicationBar(true);
				}
				else
				{
					if (this.mPivotControl.SelectedIndex == 0)
					{
						this.oldbar = SessionView.GetApplicationBar(true);
					}
					else
					{
						if (this.mPivotControl.SelectedIndex == 2)
						{
							this.getFFView();
							this.oldbar = FindFriendView.GetApplicationBar(true);
						}
						else
						{
							this.oldbar = SessionView.GetApplicationBar(true);
						}
					}
				}
			}
			else
			{
				if (this.mPivotControl.SelectedIndex == 1)
				{
					this.getContactView();
					base.get_Dispatcher().BeginInvoke(delegate
					{
						this.mContactView.init();
					});
					base.set_ApplicationBar(ContactsView.GetApplicationBar(true));
				}
				else
				{
					if (this.mPivotControl.SelectedIndex == 0)
					{
						this.getSessionView();
						base.set_ApplicationBar(SessionView.GetApplicationBar(true));
					}
					else
					{
						if (this.mPivotControl.SelectedIndex == 2)
						{
							this.getFFView();
							base.set_ApplicationBar(FindFriendView.GetApplicationBar(true));
						}
						else
						{
							if (this.mPivotControl.SelectedIndex == 3)
							{
								if (MainPage.testContactView == null)
								{
									DebugEx.timeStart("TestContactItemCtrl", 50);
									MainPage.testContactView = new TestContactItemCtrl();
									DebugEx.timeStamp();
									MainPage.testContactView.InitUI("qq250001");
									DebugEx.timeStamp();
								}
							}
							else
							{
								base.set_ApplicationBar(SessionView.GetApplicationBar(true));
							}
						}
					}
				}
			}
			this.setAppBarStyle(base.get_ApplicationBar());
		}
		private void button1_Click(object sender, RoutedEventArgs e)
		{
			new TestMsgBox
			{
				ReturnEvent = new DlgReturnEvent(this.testDlgReturn)
			}.Show();
		}
		public void testDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (dlgReturnEventArg_0 != null)
			{
				if (dlgReturnEventArg_0.mRet == Dlg_Result.Dlg_BackKey_Result)
				{
					MMMessageBox.Show("you click back key", true, "确定");
					return;
				}
				if (dlgReturnEventArg_0.mOtherArg != null)
				{
					MMMessageBox.Show("you input some arg", true, "确定");
					return;
				}
				MMMessageBox.Show("you input no arg", true, "确定");
			}
		}
		public static void goToSetting()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			if (basePage != null)
			{
				basePage.GoToPage("/Source/UI/Setting/SettingMainPage.xaml", null, false);
			}
		}
		public void UnInitMainPage()
		{
			if (this.m_WatcherNeedDoSync != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_BEGIN, this.m_WatcherNeedDoSync);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_CONTINUE, this.m_WatcherNeedDoSync);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_FINISH, this.m_WatcherNeedDoSync);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_ERR, this.m_WatcherNeedDoSync);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTOAUTH_SUCCESS, this.m_WatcherAutoAuthSuccess);
				EventCenter.removeEventWatcher(EventConst.ON_NET_BULLETIN, this.m_WatcherServerBulletin);
				EventCenter.removeEventWatcher(EventConst.ON_UI_LANGUAGE_CHANGED, this.m_WatcherLanguage);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SYNC_WEIN_STATUS, this.m_StatusChange);
				this.m_WatcherNeedDoSync = null;
				this.m_WatcherAutoAuthSuccess = null;
				this.m_WatcherServerBulletin = null;
				this.m_WatcherLanguage = null;
				this.m_StatusChange = null;
			}
			if (this.m_GetVersionOK != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_UPDATE_INFO_SUCCESS, this.m_GetVersionOK);
				this.m_GetVersionOK = null;
			}
			this.uninitAuthEventWatcher();
		}
		public static void logOut()
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			if (MainPage.mainPageInstance.mBIsLoggedOut)
			{
				return;
			}
			if (WebMMMgr.IsWebMMOnline)
			{
				WebMMMgr.IsWebMMOnline = false;
				NetSceneLogOutWebWx netSceneLogOutWebWx = new NetSceneLogOutWebWx();
				netSceneLogOutWebWx.doScene(MMLogoutWebWxOpcode.MMWEBWX_MOBILE_LOGOUT);
				MainPage.mainPageInstance.mSessionView.setWebMMState(false);
			}
			MainPage.mainPageInstance.mBIsLoggedOut = true;
			EventCenter.postEvent(EventConst.ON_ACCOUNT_LOGOUT, null, null);
			ServiceCenter.pushNotifyMgr.closePushChannel();
			PageManager.getInstance().PopAllPages(true);
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			BasePage basePage = phoneApplicationFrame.get_Content() as BasePage;
			basePage.GoToPage("/Source/UI/LoginViews/LoginMainView.xaml", null, true);
			MainPage.mainPageInstance.mContactView.logOutForContactList();
			MainPage.mainPageInstance.mSessionView.SessionUnit();
			MainPage.mainPageInstance.UnInitMainPage();
			MainPage.mainPageInstance = null;
			AccountMgr.logout();
			TileManager.SetTileNumber(0);
		}
		public static void initLogOut()
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Set_Main_Logout, strings.Set_Main_LogoutWarning, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(MainPage.logoutMsgBoxHandler);
		}
		public static void doInitLoOut()
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ProcessingCover.getProgressBar(MainPage.mainPageInstance.LayoutRoot, strings.Set_Main_Logouting, null, false, false, null);
			MainPage.mWatcherLogOut = new EventWatcher(null, null, new EventHandlerDelegate(MainPage.onInitLogOutDone));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_LOGOUT_OVER, MainPage.mWatcherLogOut);
			ServiceCenter.sceneLogout.doScene();
		}
		public static void logoutMsgBoxHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				MainPage.doInitLoOut();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private static void onInitLogOutDone(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ProcessingCover.releaseProgressBar(MainPage.mainPageInstance.LayoutRoot);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_LOGOUT_OVER, MainPage.mWatcherLogOut);
			MainPage.mWatcherLogOut = null;
			MainPage.logOut();
		}
		public static void UnInitProgram()
		{
			EventCenter.sendEvent(EventConst.ON_PROGRAM_EXIST, null);
			Log.smethod_5("MainPage", "UnInitProgram start");
			FlowControl.flushFlowSettings();
			MainPage.UnInitUI();
			StorageBasic.onFlush();
			Log.smethod_5("MainPage", "UnInitProgram end");
			Log.forceFlush();
		}
		public static void UnInitUI()
		{
			if (MainPage.mainPageInstance != null)
			{
				MainPage.mainPageInstance.SavaHistory();
			}
		}
		private void initAuthEventWatcher()
		{
			if (this.mAuthChangeWatcher == null)
			{
				this.mAuthChangeWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_AuthChange_EventHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTOAUTH_ERR, this.mAuthChangeWatcher);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_NEEDVERIFY, this.mAuthChangeWatcher);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTOAUTH_SUCCESS, this.mAuthChangeWatcher);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_SUCCESS, this.mAuthChangeWatcher);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_AUTH_ERR, this.mAuthChangeWatcher);
			}
		}
		private void uninitAuthEventWatcher()
		{
			if (this.mAuthChangeWatcher != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTOAUTH_ERR, this.mAuthChangeWatcher);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_NEEDVERIFY, this.mAuthChangeWatcher);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTOAUTH_SUCCESS, this.mAuthChangeWatcher);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_SUCCESS, this.mAuthChangeWatcher);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_AUTH_ERR, this.mAuthChangeWatcher);
				this.mAuthChangeWatcher = null;
			}
		}
		public void on_AuthChange_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			if (EventConst.ON_NETSCENE_AUTOAUTH_ERR != evtArgs.mEventID)
			{
				if (EventConst.ON_NETSCENE_AUTH_ERR != evtArgs.mEventID)
				{
					if (EventConst.ON_NETSCENE_AUTOAUTH_SUCCESS != evtArgs.mEventID)
					{
						if (EventConst.ON_NETSCENE_AUTH_SUCCESS != evtArgs.mEventID)
						{
							if (EventConst.ON_NETSCENE_AUTH_NEEDVERIFY == evtArgs.mEventID && evtArgs != null)
							{
								if (InputVCodeControl.IsShown())
								{
									InputVCodeControl.SetInputVCodeBoxWrongStage(evtArgs);
									return;
								}
								InputVCodeControl.Show(true, evtArgs, null, null, null, null);
							}
							return;
						}
					}
					ServiceCenter.sceneNewSync.doScene(7, syncScene.MM_NEWSYNC_SCENE_OTHER);
					InputVCodeControl.DismissInputVcodeBox();
					return;
				}
			}
			InputVCodeControl.DismissInputVcodeBox();
			int num = (int)evtArgs.mObject;
			if (num == -100)
			{
				Log.smethod_4(base.GetType().get_Name(), "kickout  errorId:" + num);
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.MainPage_MsgKikOut, true, "确定");
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.AuthErroMsgBoxHandler);
				return;
			}
			if (num == -999999)
			{
				App.ExitProgram();
				return;
			}
			MMMessageBox mMMessageBox2 = MMMessageBox.Show(strings.MainPage_MsgReLogin, true, "确定");
			mMMessageBox2.ReturnEvent = new DlgReturnEvent(this.AuthErroMsgBoxHandler);
		}
		public void AuthErroMsgBoxHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			MainPage.logOut();
		}
		private void disableAllControls()
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.MainPage_Opening, null, false, false, null);
		}
		private void enableAllControls()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		public static void AddOneToastToMainPage(string strToShow)
		{
			if (!ToolFunction.isBlankString(strToShow) && MainPage.sListStrToToast != null)
			{
				MainPage.sListStrToToast.Add(strToShow);
			}
		}
		private void showAllToast()
		{
			if (MainPage.sListStrToToast != null)
			{
				using (List<string>.Enumerator enumerator = MainPage.sListStrToToast.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string current = enumerator.get_Current();
						MessageBoxManager.ShowToast(current, 2500, null, false);
					}
				}
			}
			MainPage.sListStrToToast.Clear();
		}
		protected override bool IsAlertMsgNeedShow(ChatMsg chatMsg_0)
		{
			bool flag = true;
			return base.PreIsAlertMsgNeedShow(chatMsg_0, ref flag) && flag;
		}
		private void NetStatusDetectInit()
		{
			if (this.mWatcherNetStatus != null)
			{
				return;
			}
			this.mWatcherNetStatus = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerNetStatus));
			EventCenter.registerEventWatcher(EventConst.ON_NET_MM_NET_CONNECTED, this.mWatcherNetStatus);
			EventCenter.registerEventWatcher(EventConst.ON_NET_MM_NET_CONNECTING, this.mWatcherNetStatus);
			EventCenter.registerEventWatcher(EventConst.ON_NET_MM_NET_DISCONNECT, this.mWatcherNetStatus);
		}
		private void NetStatusDetectUint()
		{
			if (this.mWatcherNetStatus != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NET_MM_NET_CONNECTED, this.mWatcherNetStatus);
				EventCenter.removeEventWatcher(EventConst.ON_NET_MM_NET_CONNECTING, this.mWatcherNetStatus);
				EventCenter.removeEventWatcher(EventConst.ON_NET_MM_NET_DISCONNECT, this.mWatcherNetStatus);
				this.mWatcherNetStatus = null;
			}
		}
		private void SyncStatusDetectInit()
		{
			if (this.mWatcherSyncStatus != null)
			{
				return;
			}
			this.mWatcherSyncStatus = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerNetStatus));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SYNC, this.mWatcherSyncStatus);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADVOICE_SERVICE_FINISH, this.mWatcherSyncStatus);
		}
		private void SyncStatusDetectUnit()
		{
			if (this.mWatcherSyncStatus != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SYNC, this.mWatcherSyncStatus);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADVOICE_SERVICE_FINISH, this.mWatcherSyncStatus);
				this.mWatcherSyncStatus = null;
			}
		}
		private void onEventHandlerNetStatus(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5("MainPage", "onEventHandlerNetStatus, evtArgs.mEventID = " + evtArgs.mEventID);
			this.mSessionView.updateBulletinOnNetStatusChanged();
			if (evtArgs == null)
			{
				Log.smethod_1("MainPage", "evtArgs == null");
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_SYNC)
			{
				NetSceneSyncResult netSceneSyncResult = evtArgs.mObject as NetSceneSyncResult;
				if (netSceneSyncResult == null)
				{
					Log.smethod_1("MainPage", "NetSceneSyncResult == null");
					return;
				}
				if (netSceneSyncResult.isAppActive || netSceneSyncResult.syncCount == 0)
				{
					this.UpdateNetStatus();
					Log.smethod_5("MainPage", "UpdateNetStatus! evtArgs.mEventID = " + evtArgs.mEventID);
					return;
				}
			}
			else
			{
				this.UpdateNetStatus();
				Log.smethod_5("MainPage", "UpdateNetStatus! evtArgs.mEventID = " + evtArgs.mEventID);
			}
		}
		private void UpdateNetStatus()
		{
			ConntectorStatus connectorStatus = Connector.getConnectorStatus();
			int recvMsgStatus = ServiceCenter.sceneNewSync.getRecvMsgStatus();
			if (!NetworkDeviceWatcher.isNetworkAvailable())
			{
				this.RefreshTitle("未连接");
				return;
			}
			if (connectorStatus == ConntectorStatus.Disconnect)
			{
				if (this.canShowDisconnect)
				{
					this.RefreshTitle("未连接");
					return;
				}
				this.canShowDisconnect = true;
				return;
			}
			else
			{
				if (connectorStatus != ConntectorStatus.Connected)
				{
					this.canShowDisconnect = true;
					this.RefreshTitle("连接中");
					return;
				}
				this.canShowDisconnect = true;
				if (recvMsgStatus != 0)
				{
					this.RefreshTitle("收取中");
					return;
				}
				this.RefreshTitle("");
				this.ShowUnreadMsgCount();
				return;
			}
		}
		private void RefreshTitle(string string_0)
		{
			if (string_0 == "未连接")
			{
				this.disConnectTxt.set_Visibility(0);
				this.netStatusTxt.set_Text("");
				this.NetStatusProgressBar.set_Visibility(1);
				return;
			}
			if (string_0 == "收取中")
			{
				this.disConnectTxt.set_Visibility(1);
				this.netStatusTxt.set_Text(strings.Net_Status_GettingData);
				this.NetStatusProgressBar.set_Visibility(0);
				return;
			}
			if (string_0 == "连接中")
			{
				this.disConnectTxt.set_Visibility(1);
				this.netStatusTxt.set_Text(strings.Net_Status_Connecting);
				this.NetStatusProgressBar.set_Visibility(0);
				return;
			}
			if (string.IsNullOrEmpty(string_0))
			{
				this.disConnectTxt.set_Visibility(1);
				this.netStatusTxt.set_Text(string_0);
				this.NetStatusProgressBar.set_Visibility(1);
			}
		}
		public void ShowUnreadMsgCount(int count)
		{
			this.unReadMsgCount = count;
			if (this.unReadMsgCount != 0)
			{
				this.unreadMsgNum.set_Text("(" + this.unReadMsgCount + ")");
				this.unreadMsgNum.set_Visibility(0);
				return;
			}
			this.unreadMsgNum.set_Visibility(1);
		}
		public void ShowUnreadMsgCount()
		{
			this.ShowUnreadMsgCount(ConversationMgr.getUnReadCountAll());
		}
		public void UnLockSessionItem()
		{
			if (!this.IsNeedOnlyShowVisibleItem)
			{
				return;
			}
			this.IsNeedOnlyShowVisibleItem = false;
		}
		public void OnLanguageChange()
		{
			if (this.mSessionView == null)
			{
				return;
			}
			if (this.mFindFriendView == null)
			{
				return;
			}
			this.mSessionView.OnLanguageChange();
			this.mContactView.OnLanguageChange();
			this.mFindFriendView.OnLanguageChange();
			this.mSessionView.SessionList.RefreshAllItems<SessionListItem>();
			if (ChatContainerPage.cuChatPage != null)
			{
				ChatContainerPage.cuChatPage.mBar = null;
			}
		}
		private void btnSessionTab_Click(object sender, RoutedEventArgs e)
		{
			if (this.mPivotControl.SelectedIndex == 0)
			{
				this.mSessionView.ScrollToFirst();
				return;
			}
			this.ToIndex(0, true);
		}
		private void btnContactTab_Click(object sender, RoutedEventArgs e)
		{
			if (this.mPivotControl.SelectedIndex == 1)
			{
				this.mContactView.ScrollToFirstItem();
				return;
			}
			this.ToIndex(1, true);
		}
		private void btnFindFriendTab_Click(object sender, RoutedEventArgs e)
		{
			if (this.mPivotControl.SelectedIndex != 2)
			{
				this.ToIndex(2, true);
			}
		}
		protected override void SaveAppBar()
		{
			if (this.mPivotControl.SelectedIndex == 1)
			{
				this.oldbar = ContactsView.GetApplicationBar(true);
			}
			else
			{
				if (this.mPivotControl.SelectedIndex == 0)
				{
					this.oldbar = SessionView.GetApplicationBar(true);
				}
				else
				{
					if (this.mPivotControl.SelectedIndex == 2)
					{
						this.oldbar = FindFriendView.GetApplicationBar(true);
					}
					else
					{
						this.oldbar = SessionView.GetApplicationBar(true);
					}
				}
			}
			base.set_ApplicationBar(null);
		}
		public override List<UIElement> GetBkContents()
		{
			if (this.mUiToHideList == null)
			{
				this.mUiToHideList = new List<UIElement>();
				this.mUiToHideList.Add(this.ContentPanel);
			}
			return this.mUiToHideList;
		}
		public override Panel GetChatContainerPanel()
		{
			return this.LayoutRoot;
		}
		protected override void resumeFromChat()
		{
			this.mSessionView.Focus();
			UIDelayService.getInstance().DoDelayAction();
			this.mContactView.EnableContactRefresh();
		}
		protected override void StartRemoveBkUI()
		{
			this.mContactView.DisableContactRefresh();
		}
		protected override void StartResumeBkUI()
		{
		}
		private void startUpdateData()
		{
			if (this.mBIsUpdated)
			{
				return;
			}
			this.mBIsUpdated = true;
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.COM_HINT_UPRAGDE_DATA, null, false, false, null);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				UpdateMgr.doUpdate();
			});
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.endUpdateData();
			});
		}
		private void endUpdateData()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
			this.initPage();
			this.DoNewSync();
		}
		public static void GotoThisPage(object[] pageAgrs, bool bIsRemoveCurPage = false)
		{
			bool flag = !ConfigMgr.getBool("KeyBJustRegUser", false);
			if ((long)ConfigMgr.getInt("nVersionNumKey", 0) != (long)((ulong)ConstantsProtocol.CLIENT_VERSION))
			{
				ConfigMgr.setBool("bHasSeenWhatsNew", false);
			}
			if (!ConfigMgr.getBool("bHasSeenWhatsNew", false))
			{
				string text = "/Source/UI/WhatsnewPage.xaml";
				string text2 = PageManager.PutArg(new BasePageArg
				{
					IsRemoveLastPage = bIsRemoveCurPage,
					UserData = new object[]
					{
						flag
					}
				});
				text += string.Format("?{0}={1}", "ARGID", text2);
				((App)Application.get_Current()).RootFrame.Navigate(new Uri(text, 2));
				return;
			}
			string text3 = "/Source/UI/MainPage.xaml";
			string text4 = PageManager.PutArg(new BasePageArg
			{
				IsRemoveLastPage = bIsRemoveCurPage,
				UserData = pageAgrs
			});
			text3 += string.Format("?{0}={1}", "ARGID", text4);
			((App)Application.get_Current()).RootFrame.Navigate(new Uri(text3, 2));
			Profiler.setPoint("FirstPage");
		}
		public static void ShowProgressBar(string strWord = null)
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ProcessingCover.getProgressBar(MainPage.mainPageInstance.LayoutRoot, strWord, null, false, false, null);
		}
		public static void HideProgressBar()
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			ProcessingCover.releaseProgressBar(MainPage.mainPageInstance.LayoutRoot);
		}
		private void BindGuideInit()
		{
			if (this.mBindGuideInit != null)
			{
				return;
			}
			this.mBindGuideInit = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerBindGuide));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_FINISH, this.mBindGuideInit);
			this.mBindQQSuccessInit = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerBindSuccess));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BINDQQ_SUCCESS, this.mBindQQSuccessInit);
			this.mBindPhoneSuccessInit = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerBindSuccess));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_SUCCESS, this.mBindPhoneSuccessInit);
		}
		private void BindGuideUninit()
		{
			if (this.mBindGuideInit == null)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_PROCESS_NEWINIT_FINISH, this.mBindGuideInit);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BINDQQ_SUCCESS, this.mBindQQSuccessInit);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_SUCCESS, this.mBindPhoneSuccessInit);
		}
		private void onEventHandlerBindGuide(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			BindHintManager.CreateNewBindHintConv();
			this.FaceBookImport();
		}
		private void onEventHandlerBindSuccess(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.mSessionView.OnBindSuccess();
		}
		private void FaceBookImport()
		{
			if (!MainPage.IsRegisterFromFacebook)
			{
				return;
			}
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount == null)
			{
				return;
			}
			if (string.IsNullOrEmpty(curAccount.FBToken))
			{
				Log.smethod_5("MainPage", "currentAccount.FBToken==null");
				return;
			}
			Log.smethod_5("MainPage", "FaceBookImport");
			MainPage.IsRegisterFromFacebook = false;
			this.InitFriends();
			FBServiceCenter.fbContactMgr.getFBContact(false);
		}
		private void InitFriends()
		{
			this.friendsSuccessWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onGetFriendsSuccess));
			this.friendsFailWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onGetFriendsFail));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_GETFRIEND_SUCCESS, this.friendsSuccessWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_GETFRIEND_FAIL, this.friendsFailWatcher);
		}
		private void UnitFriends()
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_GETFRIEND_SUCCESS, this.friendsSuccessWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_GETFRIEND_FAIL, this.friendsFailWatcher);
		}
		private void onGetFriendsSuccess(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5("MainPage", "onGetFriendsSuccess");
			this.UnitFriends();
			this.CheckFaceBookImport();
		}
		private void onGetFriendsFail(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			this.UnitFriends();
		}
		private void CheckFaceBookImport()
		{
			Log.smethod_5("MainPage", "CheckFaceBookImport");
			List<FBContact> list = new List<FBContact>();
			list = StorageMgr.fbContact.getList();
			if (list != null && list.get_Count() > 0)
			{
				this.fbFriends = this.GetFriendsInFaceBook(list);
				if (this.fbFriends != null)
				{
					if (this.fbFriends.get_Count() <= 0)
					{
						return;
					}
					MMMessageBox mMMessageBox = MMMessageBox.Show("", strings.FaceBookImportInfo, true, strings.COM_Confirm, strings.COM_Cancel);
					mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnImportFaceBookHandler);
					mMMessageBox.set_Tag(this.fbFriends);
				}
				return;
			}
		}
		private void StartImportMMfriends()
		{
			if (this.fbFriends != null)
			{
				int arg_13_0 = this.fbFriends.get_Count();
			}
			this.showProgressCover(strings.FaceBookImporting);
			this.BatchAddFriendsInit();
			ServiceCenter.sceneVerifyUser.doSceneAddMultiContacts(this.fbFriends, AddContactScene.MM_ADDSCENE_FACEBOOK, "");
		}
		private void BatchAddFriendsInit()
		{
			if (this.m_WatcherAddContact != null)
			{
				return;
			}
			Log.smethod_5("MainPage", "BatchAddFriendsInit");
			this.m_WatcherAddContact = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerAddContact));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_ERR, this.m_WatcherAddContact);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS, this.m_WatcherAddContact);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_NEEDVIRIFY, this.m_WatcherAddContact);
		}
		private void BatchAddFriendsUnit()
		{
			if (this.m_WatcherAddContact == null)
			{
				return;
			}
			Log.smethod_5("MainPage", "BatchAddFriendsUnit");
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_ERR, this.m_WatcherAddContact);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS, this.m_WatcherAddContact);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_NEEDVIRIFY, this.m_WatcherAddContact);
			this.m_WatcherAddContact = null;
		}
		private void onEventHandlerAddContact(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			AddContactEventArgs addContactEventArgs = evtArgs.mObject as AddContactEventArgs;
			if (addContactEventArgs == null)
			{
				return;
			}
			Log.smethod_5("MainPage", string.Concat(new object[]
			{
				"onEventHandlerAddContact:",
				evtArgs.mEventID,
				"evtArgs.result",
				addContactEventArgs.result
			}));
			this.hideProgressCover();
			this.BatchAddFriendsUnit();
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_ADDCONTACT_ERR)
			{
				if (addContactEventArgs.result == RetConst.MM_ERR_ARG)
				{
					Dialog2BtnWithInputBox.Show(strings.Con_Detail_MsgNeedVerifyTitle, strings.Con_Detail_MsgNeedVerifyContent, strings.COM_Confirm, strings.COM_Cancel, "", new Dialog2BtnWithInputBox.dismissWithClickBtn(this.SendVerifyRequestDlg), null, null);
					return;
				}
				this.hideProgressCover();
				MMMessageBox.Show(strings.Con_Detail_MsgAddFailed, true, "确定");
				return;
			}
			else
			{
				if (evtArgs.mEventID == EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS)
				{
					this.hideProgressCover();
					MessageBoxManager.ShowToast(strings.Con_Detail_MsgAddSucc, 2500, null, false);
					return;
				}
				if (evtArgs.mEventID == EventConst.ON_NETSCENE_ADDCONTACT_NEEDVIRIFY)
				{
					Dialog2BtnWithInputBox.Show(strings.Con_Detail_MsgNeedVerifyTitle, strings.Con_Detail_MsgNeedVerifyContent, strings.COM_Confirm, strings.COM_Cancel, "", new Dialog2BtnWithInputBox.dismissWithClickBtn(this.SendVerifyRequestDlg), null, null);
				}
				return;
			}
		}
		private void SendVerifyRequestDlg(object sender, int nClickIndex)
		{
			if (nClickIndex == 0 && sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				string text = dialog2BtnWithInputBox.txtIn.get_Text();
				if (string.IsNullOrEmpty(text))
				{
					text = strings.Con_Detail_TxtVerifyInfo;
				}
				this.VerifyInit();
				ServiceCenter.sceneVerifyUser.doSceneSendMultiRequests(this.fbFriends, AddContactScene.MM_ADDSCENE_FACEBOOK, text);
				return;
			}
			this.hideProgressCover();
		}
		private void VerifyInit()
		{
			if (this.m_WatcherVerifyContact != null)
			{
				return;
			}
			Log.smethod_5("MainPage", "VerifyInit");
			this.m_WatcherVerifyContact = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerVerify));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_VERIFYUSER_SUCCESS, this.m_WatcherVerifyContact);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_VERIFYUSER_ERR, this.m_WatcherVerifyContact);
		}
		private void VerifyUnit()
		{
			if (this.m_WatcherVerifyContact == null)
			{
				return;
			}
			Log.smethod_5("MainPage", "VerifyUnit");
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_VERIFYUSER_SUCCESS, this.m_WatcherVerifyContact);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_VERIFYUSER_ERR, this.m_WatcherVerifyContact);
			this.m_WatcherVerifyContact = null;
		}
		private void onEventHandlerVerify(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			this.hideProgressCover();
			Log.smethod_5("MainPage", "onEventHandlerVerify:" + evtArgs.mEventID);
			switch (evtArgs.mEventID)
			{
			case EventConst.ON_NETSCENE_VERIFYUSER_SUCCESS:
				MessageBoxManager.ShowToast(strings.Con_Detail_MsgSendSucc, 2500, null, false);
				break;
			case EventConst.ON_NETSCENE_VERIFYUSER_ERR:
				MMMessageBox.Show(strings.Con_Detail_MsgSendFailed, true, "确定");
				break;
			}
			this.VerifyUnit();
		}
		private void OnImportFaceBookHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.StartImportMMfriends();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private List<string> GetFriendsInFaceBook(List<FBContact> fbContactList)
		{
			if (fbContactList != null && fbContactList.get_Count() > 0)
			{
				List<string> list = new List<string>();
				using (List<FBContact>.Enumerator enumerator = fbContactList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						FBContact current = enumerator.get_Current();
						if (current.nStatus == 1)
						{
							list.Add(current.strUsrName);
						}
					}
				}
				return list;
			}
			return null;
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, null, false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void regFirstSyncEvent()
		{
			if (this.mWatchFirstSync == null)
			{
				this.mWatchFirstSync = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.OnFirstSync));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SYNC, this.mWatchFirstSync);
			}
		}
		private void unRegFirstSyncEvent()
		{
			if (this.mWatchFirstSync != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SYNC, this.mWatchFirstSync);
				this.mWatchFirstSync = null;
			}
		}
		private void OnFirstSync(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			EventConst mEventID = evtArgs.mEventID;
			if (mEventID != EventConst.ON_NETSCENE_SYNC)
			{
				return;
			}
			NetSceneSyncResult netSceneSyncResult = evtArgs.mObject as NetSceneSyncResult;
			if (netSceneSyncResult != null && netSceneSyncResult.syncCount == 0)
			{
				if (netSceneSyncResult.syncStatus == SyncStatus.syncEnd)
				{
					this.unRegFirstSyncEvent();
					if (!AccountMgr.hasHeadImg)
					{
						GuideHeadSetMgr.CreateNewHintConv();
						return;
					}
					if (GuideHeadSetMgr.isShown())
					{
						GuideHeadSetMgr.deleteGuideHeadItem();
					}
				}
				return;
			}
		}
		private void guideToSetHeadImg()
		{
			if (!ConfigMgr.getBool("cStrKeyIsGuideHeadHasShown", false))
			{
				this.regFirstSyncEvent();
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/MainPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.mPivotControl = (Pivot)base.FindName("mPivotControl");
			this.gridSessionView = (Grid)base.FindName("gridSessionView");
			this.gridContactsView = (Grid)base.FindName("gridContactsView");
			this.gridFFView = (Grid)base.FindName("gridFFView");
			this.panel1Line = (panelTitleControl)base.FindName("panel1Line");
			this.unreadMsgNum = (TextBlock)base.FindName("unreadMsgNum");
			this.netStatusTxt = (TextBlock)base.FindName("netStatusTxt");
			this.disConnectTxt = (TextBlock)base.FindName("disConnectTxt");
			this.NetStatusProgressBar = (PerformanceProgressBar)base.FindName("NetStatusProgressBar");
		}
	}
}
